
import java.sql.*;
import java.io.IOException;

public class Mysql_01 {
	public static void main(String args[]) {
    Connection conn = null;
    Statement stmt = null;

    try {
			// 加载oracle驱动
      Class.forName("com.mysql.cj.jdbc.Driver");
      conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC","root","root");
      // 执行查询
      System.out.println(" 实例化Statement对象...");
      stmt = conn.createStatement();
      String sql;
      sql = "SELECT * FROM user ";
      ResultSet rs = stmt.executeQuery(sql);

      // 展开结果集数据库
      while(rs.next()){
          // 通过字段检索
          String id  = rs.getString("id");
          String name = rs.getString("nickname");

          // 输出数据
          System.out.print("ID: " + id);
          System.out.print("昵称: " + name);
          System.out.print("\n");
      }

    }catch(Exception e){
      System.out.println("有错误");
    }

    
  }
}